<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        video{
            width: 500px;
        }
    </style>
</head>
<body>
    <video src="./video.mp4" controls></video>
</body>
</html>
<script>
    //  1.记录播放位置： 节流
    const video = document.querySelector('video')
    function getItem(){
        //  currentTime 当前播放的时间
        console.log(video.currentTime)
        // 存储到  localStorage 里
       localStorage.setItem('currentTime',video.currentTime)
    }

    function throttle(fn,t){
        let timerId;
        //  这个函数会不断地触发
        return function (){
             if(!timerId){
                timerId = setTimeout(() =>{
                    fn()
                    timerId = null
                },t)
             }
        }
      }
   video.addEventListener('timeupdate',throttle(getItem,1000))

   video.addEventListener('loadeddata',function(){
    // 从本地取出 时间
    video.currentTime = localStorage.getItem('currentTime') || 0
   })
</script>